<%@ page language="java" pageEncoding="utf-8"%>
<%@page import="com.farm.web.constant.FarmConstant"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="/view/conf/farmtag.tld" prefix="PF"%>
<script type="text/javascript">
	var cpage = 1;
	//显示窗口
	function openHourFileChooseWin() {
		$('#loadMyHourFilesBoxId').show();
		doloadRemoteHourFiles(1);
	}
	//关闭窗口
	function closeHourFileChooseWin() {
		$('#loadMyHourFilesBoxId').hide();
	}
	//填充课件附件
	function chooseHourFiles(title, id) {
		closeHourFileChooseWin();
		$('#hourFileId').val(title);
		$('#hourFileIdValId').val(id);
	}

	//----------------------------------------------
	//加载远程数据
	function doloadRemoteHourFiles(page, title) {
		cpage = page;
		$('#loadMyHourFilesBoxDatas').html('');
		$.post('classweb/loadExistHourFiles.do', {
			'title' : title,
			'page' : page
		}, function(flag) {
			if (flag.STATE == 0) {
				var datasize = 0;
				$(flag.data).each(function(i, obj) {
					datasize++;
					var trhtml = intiHtmlTr(i, obj);
					$('#loadMyHourFilesBoxDatas').append(trhtml);
				});
				initfootPages(datasize, flag.pagesize);
			} else {
				alert(flag.MESSAGE);
			}
		}, 'json');

	}
	//转义html
	function encodeHtmlVar(str) {
		var temp = "";
		if (str == null || str.length == 0) {
			return "";
		}
		temp = str.replace(/&/g, "&");
		temp = temp.replace(/</g, "<");
		temp = temp.replace(/>/g, ">");
		temp = temp.replace(/\s/g, " ");
		temp = temp.replace(/\'/g, "'");
		temp = temp.replace(/\"/g, '"');
		return temp;
	}
	//构造展示表单
	function intiHtmlTr(i, obj) {
		var trhtml1 = '<tr>';
		var trhtml2 = '<td>' + encodeHtmlVar(obj.HOURTITLE) + '</td>';
		var trhtml3 = '<td>' + encodeHtmlVar(obj.FILETITLE) + '</td>';
		var trhtml4 = '<td> <button type="button" onclick=\'chooseHourFiles("'
				+ encodeHtmlVar(obj.FILETITLE) + '","' + obj.FILEID
				+ '");\' class="btn btn-primary btn-xs">选择</button></td>';
		var trhtml5 = '</tr>';
		return trhtml1 + trhtml2 + trhtml3 + trhtml4 + trhtml5;
	}
	//初始化分页参数
	function initfootPages(datasize, pagesize) {
		if (cpage > 1) {
			$('#hourfielLoadLastId').show();
		} else {
			$('#hourfielLoadLastId').hide();
		}
		if (datasize >= pagesize) {
			$('#hourfielLoadNextId').show();
		} else {
			$('#hourfielLoadNextId').hide();
		}
	}
</script>

<div id="loadMyHourFilesBoxId"
	style="border: 1px dashed #cccccc; display: none; margin: 20px; padding: 20px; font-size: 12px; background-color: #eeeeee;">
	<div class="input-group input-group-sm"
		style="width: 180px; float: left;">
		<input type="text" class="form-control" id="loarHourFilesTitle"
			placeholder="课件或附件名称..."> <span class="input-group-btn">
			<button class="btn btn-default"
				onclick="doloadRemoteHourFiles(1,$('#loarHourFilesTitle').val());"
				type="button">Go!</button>
		</span>
	</div>
	<div style="float: right; margin-top: -10px; margin-right: -10x;"
		onclick="$('#loadMyHourFilesBoxId').hide();">
		<button type="button" class="close">
			<span aria-hidden="true">×</span>
		</button>
	</div>
	<table class="table table-striped" style="margin-bottom: 0px;">
		<thead>
			<tr>
				<th>课时名称</th>
				<th>附件名称</th>
				<th style="max-width: 100px; width: 100px;"></th>
			</tr>
		</thead>
		<tbody id="loadMyHourFilesBoxDatas"
			style="height: 30px; overflow: scroll;">
		</tbody>
		<tfoot>
			<tr>
				<th colspan="3">
					<nav aria-label="...">
						<ul class="pager" style="margin: 0px;">
							<li class="previous" id="hourfielLoadLastId"><a
								onclick="doloadRemoteHourFiles(cpage-1)"><span
									aria-hidden="true">&larr;</span> 上一页</a></li>
							<li class="next" id="hourfielLoadNextId"><a
								onclick="doloadRemoteHourFiles(cpage+1)">下一页 <span
									aria-hidden="true">&rarr;</span>
							</a></li>
						</ul>
					</nav>
				</th>
			</tr>
		</tfoot>
	</table>
</div>